//go:build !integration

package test

import (
	"fmt"
	"github.com/labstack/gommon/log"
	"github.com/xeipuuv/gojsonschema"
	"path"
	"runtime"
	"testing"
)

func TestSchemes(t *testing.T) {
	_, filename, _, _ := runtime.Caller(0)
	dir := path.Join(path.Dir(filename), "..")
	log.Infof("current dir is, %s, dir", dir)

	// Act
	suits := []string{
		"schema-1",
		"schema-2",
		"schema-3",
	}
	for _, current := range suits {
		schemaLoader := gojsonschema.NewReferenceLoader(fmt.Sprintf("file://%s/test/schemas/%s/schema.json", dir, current))
		documentLoader := gojsonschema.NewReferenceLoader(fmt.Sprintf("file://%s/test/schemas/%s/example.json", dir, current))

		result, err := gojsonschema.Validate(schemaLoader, documentLoader)
		if err != nil {
			panic(err.Error())
		}
		if result.Valid() {

			log.Info("The document is valid\n")
		} else {

			log.Info("The document is invalid\n")
			for _, desc := range result.Errors() {

				log.Errorf("- %s \n", desc)
			}
		}
	}
}
